package com.ruibang.glass.iso.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.ruibang.glass.common.domain.camunda.BpmProcessInstanceCreate;
import com.ruibang.glass.iso.domain.req.TargetIndicatorsReq;
import com.ruibang.glass.iso.entity.TargetIndicators;
import com.ruibang.glass.iso.service.impl.TargetIndicatorsService;
import com.teaming.cloud.framework2.common.model.ResultBody;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * @Author: songJinKang
 * @CreateTime: 2024-06-18  20:18
 * @Description: TODO
 * @Version: 1.0
 */

@RestController
@RequestMapping("/api/iso/targetIndicators")
@Api(value = "体系目标指标控制器", tags = {"体系目标指标控制器"})
public class TargetIndicatorsController {

    @Autowired
    private TargetIndicatorsService targetIndicatorsService;

    @PostMapping("/pageQuery")
    @ApiOperation(value = "分页查询", response = ResultBody.class)
    public ResultBody<IPage<TargetIndicators>> pageQuery(@RequestBody TargetIndicatorsReq targetIndicatorsReq) {
        return ResultBody.success(targetIndicatorsService.pageQuery(targetIndicatorsReq));
    }

    @PostMapping("/save")
    @ApiOperation(value = "保存", response = ResultBody.class)
    public ResultBody save(@RequestBody @Valid TargetIndicators targetIndicators) {
        targetIndicatorsService.saveInfo(targetIndicators);
        return ResultBody.success();
    }

    @PutMapping("/edit")
    @ApiOperation(value = "修改", response = ResultBody.class)
    public ResultBody edit(@RequestBody @Valid TargetIndicators targetIndicators) {
        targetIndicatorsService.edit(targetIndicators);
        return ResultBody.success();
    }

    @DeleteMapping("/deleteById/{id}")
    @ApiOperation(value = "根据ID删除", response = ResultBody.class)
    public ResultBody save(@PathVariable String id) {
        targetIndicatorsService.removeById(id);
        return ResultBody.success();
    }

    @PostMapping("/startProcess")
    @ApiOperation(value = "根据ID删除", response = ResultBody.class)
    public ResultBody startProcess(@RequestBody BpmProcessInstanceCreate bpmProcessInstanceCreate) {
        targetIndicatorsService.startProcess(bpmProcessInstanceCreate);
        return ResultBody.success();
    }
}
